/* eslint-disable no-param-reassign */
import brandApi from '@/api/modules/system/brandMana'
const state = {
  brandData: [],
  brandFilterData: [],
  newBrandData: {

  }
}
const mutations = {
  SET_BRAND_DATA (state, val) {
    state.brandData = val
  },
  SET_BRANDFilter_DATA (state, val) {
    state.brandFilterData = val
  }
}

const actions = {
  getBrandData ({ commit }) {
    commit('SET_BRAND_DATA', [])
    return new Promise((resolve, reject) => {
      brandApi.getAllBrand({ selectAll: true }).then(res => {
        commit('SET_BRAND_DATA', res.data)
        resolve(true)
      }).catch(err => {
        reject(err)
      })
    })
  },
  getBrandFilterData ({ commit }) {
    commit('SET_BRANDFilter_DATA', [])
    return new Promise((resolve, reject) => {
      brandApi.getAllBrand().then(res => {
        commit('SET_BRANDFilter_DATA', res.data)
        resolve(true)
      }).catch(err => {
        reject(err)
      })
    })
  }
}
const getters = {
  getBrandObj (state) {
    const obj = {}
    state.brandData.forEach(item => {
      obj[item.id] = item.name
    })
    return obj
  }
}
export default {
  state,
  mutations,
  actions,
  getters
}
